import request from './request';
import {HOST_URL} from './config'
// 测试
export const fetchData = query => {
    return request({
        url: './table.json',
        method: 'get',
        params: query
    });
};

// 1.0 用户接口
// 用户注册
export const register = (data={})=>{
    return request.post(`${HOST_URL}/user/register`,data,{headers: {token: localStorage.getItem('auto_token')}});
}
// 用户登录
export const login = (data={})=>{
    return request.post(`${HOST_URL}/user/login`,data,{headers: {token: localStorage.getItem('auto_token')}});
}
// 修改用户资料
export const modify = (data={})=>{
    return request.post(`${HOST_URL}/user/modify`,data,{headers: {token: localStorage.getItem('auto_token')}});
}
// 获取用户资料
export const getUserInfo = (data={})=>{
    return request.post(`${HOST_URL}/user/user_info`,data,{headers: {token: localStorage.getItem('auto_token')}});
}
// 2.0 管理员接口
// 管理员注册
export const registerAdmin = (data={})=>{
    return request.post(`${HOST_URL}/admin/register`,data,{headers: {token: localStorage.getItem('auto_token')}});
}
// 管理员登录
export const loginAdmin = (data={})=>{
    return request.post(`${HOST_URL}/admin/login`,data,{headers: {token: localStorage.getItem('auto_token')}});
}
// 修改用户资料
export const modifyAdmin = (data={})=>{
    return request.post(`${HOST_URL}/admin/modify`,data,{headers: {token: localStorage.getItem('auto_token')}});
}
// 获取用户资料
export const getUserInfoAdmin = (data={})=>{
    return request.post(`${HOST_URL}/admin/admin_info`,data,{headers: {token: localStorage.getItem('auto_token')}});
}
// 管理员获取用户列表
export const getUserList = (data={})=>{
    return request.get(`${HOST_URL}/admin/list`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}
// 管理员获取用户总数
export const getUserTotal = (data={})=>{
    return request.get(`${HOST_URL}/admin/total`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}
// 管理员搜索用户
export const searchUser = (data={})=>{
    return request.get(`${HOST_URL}/admin/search`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}
// 管理员删除用户
export const deleteUser = (data={})=>{
    return request.post(`${HOST_URL}/admin/delete`,data,{headers: {token: localStorage.getItem('auto_token')}});
}

// 3.0 题库接口
// 添加题库
// 参数：topic_lib_name, topic_count, topic_lib_single_count, topic_lib_multi_count, topic_lib_judge_count, exam_time, exam_type
export const topicLibAdd = (data={})=>{
    return request.post(`${HOST_URL}/topic_lib/add`,data,{headers: {token: localStorage.getItem('auto_token')}});
}
// 删除题库（用户删除）
// 参数：topic_lib_id user_id
export const topicLibRemove = (data={})=>{
    return request.post(`${HOST_URL}/topic_lib/remove`,data,{headers: {token: localStorage.getItem('auto_token')}});
}
// 删除题库（管理员删除）
// 参数：topic_lib_id
export const topicLibDelete = (data={})=>{
    return request.post(`${HOST_URL}/topic_lib/delete`,data,{headers: {token: localStorage.getItem('auto_token')}});
}
// 题库列表 1（管理员）
// 参数：page_num, page_size
export const topicLibList = (data={})=>{
    return request.get(`${HOST_URL}/topic_lib/list`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}

// 题库列表 2
// 参数：无
export const topicLibList2 = (data={})=>{
    return request.get(`${HOST_URL}/topic_lib/list2`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}

// 题库列表 3 （用户）
// 参数：page_num, page_size
export const topicLibList3 = (data={})=>{
    return request.get(`${HOST_URL}/topic_lib/list3`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}

// 题库详情
// 参数：topic_lib_id
export const topicLibDetail = (data={})=>{
    return request.get(`${HOST_URL}/topic_lib/detail`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}

// 搜索题库
// 参数：keyword
export const topicLibSearch = (data={})=>{
    return request.get(`${HOST_URL}/topic_lib/search`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}

// 题库总数量
// 参数：无
export const topicLibTotal = (data={})=>{
    return request.get(`${HOST_URL}/topic_lib/total`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}

// 题库总数量(管理员)
// 参数：无
export const topicLibTotal2 = (data={})=>{
    return request.get(`${HOST_URL}/topic_lib/total2`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}
// 发布题库
// 参数：无
export const topicLibPublish = (data={})=>{
    return request.get(`${HOST_URL}/topic_lib/publish`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}

// 获取题库
// 参数：无
export const getTopicLibPublish = (data={})=>{
    return request.get(`${HOST_URL}/topic_lib/get_publish`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}

// 4. 题目接口
// 添加题目
// 参数：user_name, topic_type, topic_content, topic_analysis, exam_time, exam_type, topic_lib_id,topic_options,topic_val
export const topicAdd = (data={})=>{
    return request.post(`${HOST_URL}/topic/add`,data,{headers: {token: localStorage.getItem('auto_token')}});
}
// 删除题目（用户删除）
// 参数：topic_id user_id
export const topicRemove = (data={})=>{
    return request.post(`${HOST_URL}/topic/remove`,data,{headers: {token: localStorage.getItem('auto_token')}});
}
// 删除题目（管理员删除）
// 参数：topic_id
export const topicDelete = (data={})=>{
    return request.post(`${HOST_URL}/topic/delete`,data,{headers: {token: localStorage.getItem('auto_token')}});
}
// 题目列表
// 参数：page_num, page_size
export const topicList = (data={})=>{
    return request.get(`${HOST_URL}/topic/list`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}
// 题目详情
// 参数：topic_id
export const topicDetail = (data={})=>{
    return request.get(`${HOST_URL}/topic/detail`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}

// 搜索题目
// 参数：keyword
export const topicSearch = (data={})=>{
    return request.get(`${HOST_URL}/topic/search`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}

// 题目总数量
// 参数：无
export const topicTotal = (data={})=>{
    return request.get(`${HOST_URL}/topic/total`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}

// 题目总数量
// 参数：topic_lib_id, topic_type
export const topicTypeTotal = (data={})=>{
    return request.post(`${HOST_URL}/topic/topic_type_total`,data,{headers: {token: localStorage.getItem('auto_token')}});
}

// 5. 考试接口
// 删除考试（用户删除）
// 参数：topic_lib_id user_id
export const examRemove = (data={})=>{
    return request.post(`${HOST_URL}/exam/remove`,data,{headers: {token: localStorage.getItem('auto_token')}});
}
// 删除考试（管理员删除）
// 参数：topic_lib_id
export const examDelete = (data={})=>{
    return request.post(`${HOST_URL}/exam/delete`,data,{headers: {token: localStorage.getItem('auto_token')}});
}
// 考试列表 1
// 参数：page_num, page_size
export const examList = (data={})=>{
    return request.get(`${HOST_URL}/exam/list`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}

// 考试列表 2
// 参数：无
export const examList2 = (data={})=>{
    return request.get(`${HOST_URL}/exam/list2`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}

// 考试列表 3
// 参数：page_num, page_size
export const examList3 = (data={})=>{
    return request.get(`${HOST_URL}/exam/list3`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}

// 考试详情
// 参数：topic_lib_id
export const examDetail = (data={})=>{
    return request.get(`${HOST_URL}/exam/detail`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}

// 搜索考试
// 参数：keyword
export const examSearch = (data={})=>{
    return request.get(`${HOST_URL}/exam/search`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}

// 考试总数量
// 参数：无
export const examTotal = (data={})=>{
    return request.get(`${HOST_URL}/exam/total`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}


// 6.0 成绩接口
// 添加成绩
// 参数：user_name, score_val, score_exam_time, exam_options, exam_time, exam_type, topic_lib_id, exam_id, exam_name, exam_fullcredit, exam_passline 
export const scoreAdd = (data={})=>{
    return request.post(`${HOST_URL}/score/add`,data,{headers: {token: localStorage.getItem('auto_token')}});
}
// 删除成绩（用户删除）
// 参数：score_id user_id
export const scoreRemove = (data={})=>{
    return request.post(`${HOST_URL}/score/remove`,data,{headers: {token: localStorage.getItem('auto_token')}});
}
// 删除成绩（管理员删除）
// 参数：score_id
export const scoreDelete = (data={})=>{
    return request.post(`${HOST_URL}/score/delete`,data,{headers: {token: localStorage.getItem('auto_token')}});
}
// 成绩列表
// 参数：page_num, page_size
export const scoreList = (data={})=>{
    return request.get(`${HOST_URL}/score/list`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}
// 成绩详情
// 参数：score_id
export const scoreDetail = (data={})=>{
    return request.get(`${HOST_URL}/score/detail`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}

// 搜索成绩
// 参数：keyword
export const scoreSearch = (data={})=>{
    return request.get(`${HOST_URL}/score/search`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}

// 统计考试记录总数量
// 参数：无
export const scoreTotal = (data={})=>{
    return request.get(`${HOST_URL}/score/total`,{params:data,headers: {token: localStorage.getItem('auto_token')}});
}

// 是否已经考试
// 参数：score_id
export const scorePartake = (data={})=>{
    return request.post(`${HOST_URL}/score/partake`,data,{headers: {token: localStorage.getItem('auto_token')}});
}